﻿<!DOCTYPE html>
<html>
<head>
    <link rel="shortcut icon" href="images/app_logo.png" type="image/x-icon"/>
    <title>客户信息详情</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>

    <!-- bootstrap & fontawesome -->
    <link rel="stylesheet" href="assets/css/bootstrap.min.css" />
    <link rel="stylesheet" href="assets/font-awesome/4.2.0/css/font-awesome.min.css" />

    <!-- page specific plugin styles -->

    <!-- text fonts -->
    <link rel="stylesheet" href="assets/fonts/fonts.googleapis.com.css" />

    <!-- ace styles -->
    <link rel="stylesheet" href="assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />

    <!--[if lte IE 9]>
    <link rel="stylesheet" href="assets/css/ace-part2.min.css" class="ace-main-stylesheet" />
    <![endif]-->

    <!-- ace settings handler -->
    <script src="assets/js/ace-extra.min.js"></script>

</head>
<body class="no-skin">
<div id="navbar" class="navbar navbar-default">
    <script type="text/javascript">
        try{ace.settings.check('navbar' , 'fixed')}catch(e){}
    </script>

   <#include "header.ftl"/>
</div>

<div class="main-container" id="main-container">
    <script type="text/javascript">
        try{ace.settings.check('main-container' , 'fixed')}catch(e){}
    </script>

    <div id="sidebar" class="sidebar responsive">
        <script type="text/javascript">
            try{ace.settings.check('sidebar' , 'fixed')}catch(e){}
        </script>
        <#include "left_list_menu.ftl" />
        <div class="sidebar-toggle sidebar-collapse" id="sidebar-collapse">
            <i class="ace-icon fa fa-angle-double-left" data-icon1="ace-icon fa fa-angle-double-left" data-icon2="ace-icon fa fa-angle-double-right"></i>
        </div>

        <script type="text/javascript">
            try{ace.settings.check('sidebar' , 'collapsed')}catch(e){}
        </script>
    </div>


    <div class="main-content">
        <div class="main-content-inner">

            <div class="page-content">
                <div class="page-header">
                    <h1>
                        客户信息管理
                        <small>
                            <i class="ace-icon fa fa-angle-double-right"></i>
                            <a href="customer.html">客户信息列表</a>
                        </small>
                        <small>
                            <i class="ace-icon fa fa-angle-double-right"></i>
                            客户信息详情
                        </small>
                    </h1>
                </div><!-- /.page-header -->

                <!-- 客户基本信息 -->
                <div class="row">
                    <div class="col-xs-12 col-sm-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h4 class="panel-title">
                                    基本信息
                                    <button type="button" class="btn btn-primary btn-xs" id="saveInfo" style="float: right;margin-top:-6px;"> 保 存 </button>
                                </h4>
                            </div>
                            <div class="panel-body">
                                <form role="form" id="info" class="form-horizontal">
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">名称 :</label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control" id="customer_name" name="customer_name" placeholder=""/>
                                        </div>
                                        <p class="form-control-static col-sm-1" style="color:red">*</p>
                                        <label class="col-sm-2 control-label">创建日期 :</label>
                                        <div class="col-sm-4">
                                            <input type="text" class="form-control" readonly id="createtimeStr" name="" placeholder=""/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">性别 :</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" id="customer_sex" name="customer_sex"></select>
                                        </div>
                                        <label class="col-sm-3 control-label">所属门店 :</label>
                                        <div class="col-sm-4">
                                            <select class="form-control" disabled id="shop_id" name="shop_id"></select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">电话 :</label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control"  onkeyup="value=value.replace(/[^\d]/g,'')" id="customer_phone" name="customer_phone" placeholder=""/>
                                        </div>

                                        <p class="form-control-static col-sm-1" style="color:red">*</p>
                                        <label class="col-sm-2 control-label">状态 :</label>
                                        <div class="col-sm-4">
                                            <select class="form-control " disabled id="customer_type" name="customer_type"></select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">编号 :</label>
                                        <div class="col-sm-3">
                                            <p class="form-control-static" id="customer_id" ></p>
                                        </div>
                                        <label class="col-sm-3 control-label">余额 :</label>
                                        <div class="col-sm-3">
                                            <p class="form-control-static" id="customer_balance"></p>
                                        </div>
                                    </div>


                                </form>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 房产信息 -->
                <div class="row">
                    <div class="col-xs-12 col-sm-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h4 class="panel-title">房产信息
                                    <button type="button" data-toggle="modal" data-target="#addHouse" class="btn btn-primary btn-xs" style="float:right;margin-top:-6px;">添加房产</button>
                                </h4>
                            </div>
                            <div class="panel-body" style="padding:0px">
                                <!-- datatable 表 -->
                                <div class="row">
                                    <div class="col-xs-12">
                                        <!-- PAGE CONTENT BEGINS -->
                                        <div class="row">
                                            <div class="col-xs-12">
                                                <table id="dynamic-table" class="table table-striped table-bordered table-hover">
                                                    <thead>
                                                    </thead>
                                                    <tbody>
                                                    </tbody>
                                                </table>
                                            </div><!-- /.span -->
                                        </div><!-- /.row -->
                                    </div><!-- /.col -->
                                </div><!-- /.row -->
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 添加房产 -->
                <div class="modal fade" id="addHouse" data-backdrop="static">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal">
                                    <span aria-hidden="true">&times;</span><span class="sr-only">close</span>
                                </button>
                                <h4 class="modal-title">添加房产</h4>
                            </div>
                            <div class="modal-body">
                                <form role="form" id="addHouseForm" class="form-horizontal">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">面积 :</label>
                                        <div class="col-sm-4">
                                            <input type="text" class="form-control" name="house_area" placeholder=""/>
                                        </div>
                                        <p class="col-sm-2 form-control-static">单位：平米</p>
                                        <p class="form-control-static col-sm-1" style="color:red">*</p>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">房型 :</label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control" name="room_type" placeholder=""/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">地址 :</label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control" name="house_address" placeholder=""/>
                                        </div>
                                        <p class="form-control-static col-sm-1" style="color:red">*</p>
                                    </div>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-primary btn-sm" id="saveHouse">保存</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 编辑房产 -->
                <div class="modal fade" id="editHouse">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close">
                                    <span aria-hidden="true" data-dismiss="modal">&times;</span><span class="sr-only">close</span>
                                </button>
                                <h4 class="modal-title">修改房产信息</h4>
                            </div>
                            <div class="modal-body">
                                <form role="form" id="editHouseForm" class="form-horizontal">
                                    <div class="form-group">
                                        <label class="control-label col-sm-3">地址</label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control" id="house_address" name="house_address" placeholder="">
                                        </div>
                                        <p class="form-control-static col-sm-1" style="color:red">*</p>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-sm-3">房型</label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control" id="room_type" name="room_type"  placeholder="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-sm-3">面积</label>
                                        <div class="col-sm-4">
                                            <input type="text" class="form-control" id="house_area" name="house_area" onkeyup="value=value.replace(/[^\d]/g,'')">
                                        </div>
                                        <p class="col-sm-2 form-control-static">平米</p>
                                        <p class="form-control-static col-sm-1" style="color:red">*</p>
                                    </div>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-primary btn-sm" id="saveEditHouseForm">保存</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 添加订单 -->
                <div class="modal fade" id="addOrder" data-backdrop="static">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal">
                                    <span aria-hidden="true">&times;</span><span class="sr-only">close</span>
                                </button>
                                <h4 class="modal-title">选择订单类型</h4>
                            </div>
                            <div class="modal-body">
                                <p>请选择您要添加的大订单类型：</p>
                                <form role="form" id="addOrderForm" class="form-horizontal">
                                    <div class="form-group text-left" style="margin:20px">
                                        <button type="button" class="btn btn-primary btn-sm" style="margin-right: 25px;" id="yOrder">一次性订单</button>
                                        <button type="button" class="btn btn-primary btn-sm" style="margin-right: 25px;" id="hOrder">合同订单</button>
                                        <button type="button" class="btn btn-primary btn-sm" style="margin-right: 25px;" id="bOrder">包月订单</button>
                                        <button type="button" class="btn btn-primary btn-sm" id="mOrder">免费订单</button>
                                    </div>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-primary btn-sm" data-dismiss="modal">取消</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 优惠券信息 -->
                <div class="row">
                    <div class="col-xs-12 col-sm-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h4 class="panel-title">优惠券信息
                                </h4>
                            </div>
                            <div class="panel-body" style="padding:0px">
                                <!-- datatable 表 -->
                                <div class="row">
                                    <div class="col-xs-12">
                                        <!-- PAGE CONTENT BEGINS -->
                                        <div class="row">
                                            <div class="col-xs-12">
                                                <table id="dynamic-table1" class="table table-striped table-bordered table-hover">
                                                    <thead>
                                                    </thead>
                                                    <tbody>
                                                    </tbody>
                                                </table>
                                            </div><!-- /.span -->
                                        </div><!-- /.row -->
                                    </div><!-- /.col -->
                                </div><!-- /.row -->
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 编辑优惠券 -->
                <div class="modal fade" id="editCoupon" data-backdrop="static">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal">
                                    <span aria-hidden="true">&times;</span><span class="sr-only">close</span>
                                </button>
                                <h4 class="modal-title">编辑优惠券</h4>
                            </div>
                            <div class="modal-body">
                                <form role="form" id="addForm" class="form-horizontal">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">状态 :</label>
                                    <div class="col-sm-4">
                                        <select class="form-control" id="couponstatus" name="couponstatus"></select>
                                        <span style="display: none;" id="coupon_state"></span>
                                    </div>
                                    <br/>
                                </div>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-primary btn-sm" id="saveCouponid" >保存</button>
                                <button type="button" class="btn btn-primary btn-sm" data-dismiss="modal">取消</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <div class="footer">
        <div class="footer-inner">
            <div class="footer-content">

            </div>
        </div>
    </div>

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
</div><!-- /.main-container -->

<!-- basic scripts -->

<!--[if !IE]> -->
<script src="assets/js/jquery.2.1.1.min.js"></script>

<!-- <![endif]-->

<!--[if IE]>
<script src="assets/js/jquery.1.11.1.min.js"></script>
<![endif]-->

<!--[if !IE]> -->
<script type="text/javascript">
    window.jQuery || document.write("<script src='assets/js/jquery.min.js'>"+"<"+"/script>");
</script>

<!-- <![endif]-->

<!--[if IE]>
<script type="text/javascript">
    window.jQuery || document.write("<script src='assets/js/jquery1x.min.js'>"+"<"+"/script>");
</script>
<![endif]-->
<script type="text/javascript">
    if('ontouchstart' in document.documentElement) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
</script>
<script src="assets/js/bootstrap.min.js"></script>

<!-- page specific plugin scripts -->
<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/jquery.dataTables.bootstrap.min.js"></script>
<script src="assets/js/dataTables.tableTools.min.js"></script>
<script src="assets/js/dataTables.colVis.min.js"></script>

<!--<script src="http://cdn.bootcss.com/bootstrap-table/1.9.1/bootstrap-table.min.js"></script>-->

<!-- ace scripts -->
<script src="assets/js/ace-elements.min.js"></script>
<script src="assets/js/ace.min.js"></script>

<!-- change style -->
<link rel="stylesheet" href="css/config.css">
<!-- 配置接口地址信息 -->
<script src="js/config.js"></script>

<!--<script src="js/tableexport.js"></script>-->

<!-- inline scripts related to this page -->
<script type="text/javascript">
    //获取接口地址
    var interfaceAddress = getPort();
    var urlPara = new parseQueryString(window.location.search);
    var customer_id = urlPara.customer_id;
    var admin_id = getCookieValue("admin_id");
    var isUpdate = 0;
    var customer_type;
    var id;
    var couponstatus;


    jQuery(function($) {
        setOption();
        loadData();
        couponData();//优惠券
        setOption1();//动态加载
        //获取id
        $("#customer_id").html("K"+customer_id);
        //请求数据
        function loadData(){
            //获取客户房产列表
            $.ajax({
                type:'POST',
                url:interfaceAddress+"houseList",
                data:[
                    { name: "admin_id", value: admin_id },
                    { name: "customer_id", value: customer_id },
                ],
                dataType:'json',
                beforeSend: function () {
                    initial_wait();
                },
                success:function(data){
                    closeWaitDialog();
                    if (data.status == "200") {
                        var list = data.data.list;
                        setTable(list);
                    }else{
                        alert(data.info);
                    }
                },
                error: function () {
                    closeWaitDialog();
                    alert("服务端出错！");
                }
            });
        }


        /* ---------------------------------------------------- datatable表 ------------------------------------------------ */
        function setTable(aa){
            var f;//用于标记详情页被点击
            //重定义datatable
            var oTable =
            $("#dynamic-table").dataTable({
                "destroy":true,//消除重定义出错
                "bPaginate":false,//是否使用分页
                "bFilter": false, //是否使用搜索
                "sInfo":true,
                "bAutoWidth":false,
                "serverSide": false,
                "oLanguage":{
                    "sInfo": "显示 _START_ 至 _END_ 条 &nbsp;&nbsp;共 _TOTAL_ 条",
                    "sZeroRecords":"没有数据！",
                    "oPaginate": {
                        "sPrevious": " 上一页 ",
                        "sNext":     " 下一页 ",
                    }
                },
                "aoColumns":[
                    {"data":"house_id","sTitle":"客户房产id","sClass":"displayCol","bSortable":false},
                    {"data":"house_address","sTitle":"地址","bSortable":false},
                    {"data":"room_type","sTitle":"房型","bSortable":false},
                    {"data":"house_area","sTitle":"面积 ( 单位平米 )"},
                    {"data":" ","sTitle":"操作","bSortable":false,
                        "mRender":function(data,type,full){
                            return "<div class='action-buttons'>" +
                                    "<button id='edit' class='btn btn-primary btn-xs' style='margin-right:10px' title='编辑'>编辑</button>" +
                                    "<button id='delete' class='btn btn-danger btn-xs' style='margin-right:10px' title='删除'>删除</button>" +
                                    "<button id='add' class='btn btn-success btn-xs' style='margin-right:10px' title='添加订单'>添加订单</button>" +
                                    "</div>";
                        }}
                ],
                "aaData":aa,
            });
            $("body").delegate('#dynamic-table tr #edit', 'click', function () {
                f = 1;
            });
            $("body").delegate('#dynamic-table tr #delete', 'click', function () {
                f = 2;
            });
            $("body").delegate('#dynamic-table tr #add', 'click', function () {
                f = 3;
            });
            $("body").delegate('#dynamic-table tr', 'click', function () {
                var colData = oTable.fnGetData(this);
                if(colData != null){
                    house_id = colData.house_id;
                    var house_address = colData.house_address;
                }
                if(f == 1){//编辑
                    $("#editHouse").modal({
                        "backdrop":"static",
                        "keyboard":"true"
                    });
                    fillInfo(colData);
                }else if(f == 2){//删除
                    var require = confirm("确认删除房产信息吗");
                    if(require == true){
                        delHouse();
                    }else
                        f = 0;
                }else if(f == 3){//添加订单
                    $("#addOrder").modal({});
                    var c = "house_id="+house_id+"&customer_id="+customer_id+"&house_address="+house_address;
                    var d = encodeURIComponent(c);
                    //添加一次性订单
                    $("#yOrder").on("click", function () {
                        var urlOpen = "add_y_order.html?"+d+"&order_type=3";
                        //var urlOpen = "add_yhm_order.html?"+d+"&order_type=3";
                        window.open(urlOpen,"_self");
                    });
                    //添加合同订单
                    $("#hOrder").on("click", function () {
                        //var urlOpen = "add_h_order.html?"+d;
                        var urlOpen = "add_h_order.html?"+d+"&order_type=1";
                        window.open(urlOpen,"_self");
                    });
                    //添加包月订单
                    $("#bOrder").on("click", function () {
                        var urlOpen = "add_b_order.html?"+d+"&order_type=2";
                        window.open(urlOpen,"_self");
                    });
                    //添加免费订单
                    $("#mOrder").on("click", function () {
                        //var urlOpen = "addorder.html?"+d;
                        var urlOpen = "add_y_order.html?"+d+"&order_type=4";
                        window.open(urlOpen,"_self");
                    });
                }
            });
        }



        /* ---------------------------------------------------- 添加，修改,删除,添加订单 ------------------------------------------------ */
        //修改基本信息
        $("#saveInfo").click(function(){
            var customer_name = $("#info input[name='customer_name']").val();
            var customer_phone = $("#info input[name='customer_phone']").val();
            if(customer_name == ""){
                alert("请输入名称");
                return false;
            }
            if(customer_phone == ""){
                alert("请输入电话");
                return false;
            }
            var c = $("#info").serialize();
            debugger;
            //return false;
            $.ajax({
                type:"POST",
                url:interfaceAddress+"updateCustomer?admin_id="+admin_id+"&customer_id="+customer_id+"&isUpdate="+isUpdate+"&customer_type="+customer_type,
                data:$("#info").serialize(),
                async:true,
                dataType:"json",
                beforeSend: function () {
                    initial_deal();
                },
                success:function(d){
                    closeWaitDialog();
                    if(d.status == "200"){
                        alert("保存成功！");
                        window.location.reload();
                    }else{
                        alert(d.info);
                    }
                },
                error: function () {
                    closeWaitDialog();
                    alert("服务端出错！");
                }
            });
        });
        //添加房产
        $("#saveHouse").click(function () {
            var room_type = $("#addHouseForm input[name='room_type']").val();
            var house_address = $("#addHouseForm input[name='house_address']").val();
            var house_area = $("#addHouseForm input[name='house_area']").val();
            if(house_area == ""){
                alert("请输入面积!");
                return false;
            }
            if(isNaN(house_area)){
                alert("面积必须为数字!");
                return false;
            }/*
            if(room_type == ""){
                alert("请输入房型!");
                return false;
            }*/
            if(house_address == ""){
                alert("请输入地址!");
                return false;
            }
            $.ajax({
                type:"POST",
                url:interfaceAddress+"addHouse?admin_id="+admin_id+"&customer_id="+customer_id,
                data:$("#addHouseForm").serialize(),
                async:true,
                dataType:"json",
                beforeSend: function () {
                    initial_deal();
                },
                success:function(data){
                    closeWaitDialog();
                    if(data.status == "200"){
                        alert("添加成功！");
                        window.location.reload();
                    }else{
                        alert(data.info);
                    }
                },
                error: function () {
                    closeWaitDialog();
                    alert("服务端出错！");
                }
            });
        });
        //编辑房产
        $("#saveEditHouseForm").click(function(){
            var room_type = $("#editHouseForm input[name='room_type']").val();
            var house_address = $("#editHouseForm input[name='house_address']").val();
            var house_area = $("#editHouseForm input[name='house_area']").val();
            if(house_area == ""){
                alert("请输入面积!");
                return false;
            }
            if(isNaN(house_area)){
                alert("面积必须为数字!");
                return false;
            }
            if(house_address == ""){
                alert("请输入地址!");
                return false;
            }
            $.ajax({
                type:"POST",
                url:interfaceAddress+"updateHouse?admin_id="+admin_id+"&customer_id="+customer_id+"&house_id="+house_id,
                data:$("#editHouseForm").serialize(),
                async:true,
                dataType:"json",
                beforeSend: function () {
                    initial_deal();
                },
                success:function(data){
                    closeWaitDialog();
                    if(data.status == "200"){
                        alert("修改成功！");
                        window.location.reload();
                    }else{
                        alert(data.info);
                    }
                },
                error: function () {
                    closeWaitDialog();
                    alert("服务端出错！");
                }
            });
        });
        //删除房产
        function delHouse(){
            $.ajax({
                type:"POST",
                url:interfaceAddress+"delHouse?admin_id="+admin_id+"&house_id="+house_id,
                async:true,
                dataType:"json",
                beforeSend: function () {
                    initial_deal();
                },
                success:function(data){
                    closeWaitDialog();
                    if(data.status == "200"){
                        alert("删除成功！");
                        window.location.reload();
                    }else{
                        alert(data.info);
                    }
                },
                error: function () {
                    closeWaitDialog();
                    alert("服务端出错！");
                }
            });
        }
        $("#customer_phone").change(function () {
            isUpdate = 1;
        });



        /* ---------------------------------------------------- 加载下拉框,基本信息 ------------------------------------------------ */
        function setOption(){
            var customer_type = get_customer_type();
            var customer_sex = get_customer_sex();
            fillOption1("customer_type",customer_type);
            fillOption1("customer_sex",customer_sex);
            $.ajax({
                url:interfaceAddress+"getAllShopAndTrain",
                type:'POST',
                dataType:'json',
                data:[
                    { name: "admin_id", value: admin_id },
                ],
                beforeSend: function () {
                    initial_wait();
                },
                success:function(data){
                    closeWaitDialog();
                    if (data.status == "200") {
                        var shops = shopFormate(data.data.shop_list);
                        fillOption1("shop_id",shops);
                        fillData();
                    }else{
                        alert(data.info);
                        return false;
                    }
                },
                error: function () {
                    closeWaitDialog();
                    alert("服务端出错！");
                    return false;
                }
            });
        }
        function fillData(){
            $.ajax({
                url:interfaceAddress+"customerList",
                type:'POST',
                dataType:'json',
                data:[
                    { name: "admin_id", value: admin_id },
                    { name: "customer_id_key", value: 0 },
                    { name: "customer_type", value: 0 },
                    { name: "warm_type", value: 0 },
                    { name: "shop_id", value: 0 }
                ],
                beforeSend: function () {
                    initial_wait();
                },
                success:function(d){
                    closeWaitDialog();
                    if (d.status == "200") {
                        var d = d.data.list;
                        var info;
                        var customer_balance = {};

                        var l = d.length;
                        if(l != 0){
                            for(var i=0;i< l;i++){
                                var obj = d[i];
                                $.each(obj, function (k,v) {
                                    if(k == "customer_id"){
                                        if(v == customer_id){
                                            info = d[i];
                                        }
                                    }
                                });
                            }
                            if(info == undefined){
                                alert("找不到该客户信息详情!");
                                return false;
                            }
                            //debugger;
                            $.each(info, function (k,v) {
                                        if(k == "createtimeStr"){
                                            info.createtimeStr = getLocalTime(v);
                                        }
                                        if(k == "customer_balance"){
                                            customer_balance.customer_balance = v;

                                }

                                if(k == "customer_type"){
                                    customer_type = v;
                                }
                            });
                            //debugger;
                            fillInfo(info);
                            fillInfoA(customer_balance);
                        }
                    }else{
                        alert(d.info);
                    }
                },
                error: function () {
                    closeWaitDialog();
                    alert("服务端出错！");
                }
            });
        }



        //优惠券请求数据
        function  couponData(){
            //获取客户房产列表
            $.ajax({
                type:'POST',
                url:interfaceAddress+"couponList",
                data:[
                    { name: "admin_id", value: admin_id },
                    { name: "customer_id", value: customer_id },
                ],
                dataType:'json',
                beforeSend: function () {
                    initial_wait();
                },
                success:function(data){
                    console.log(data);
                    closeWaitDialog();
                    if (data.status == "200") {
                        var list =dataFormate(data.data.list);
                        setTable1(list);
                    }else{
                        alert(data.info);
                    }
                },
                error: function () {
                    closeWaitDialog();
                    alert("服务端出错！");
                }
            });
        }
        function dataFormate(list){
            var d = list;
            for(var i=0;i< d.length;i++){
                var obj = d[i];
                $.each(obj, function (k,v) {
                    if(k == "couponstatus"){
                        if(v == "1"){
                            d[i]["status"] = "未使用";
                        }else if(v == "2"){
                            d[i]["status"] = "已使用 ";
                        }
                        else if(v=="3"){
                            d[i]["status"] = "未激活";
                        }
                    }

                });
            }
            return d;
        }
        //编辑优惠券
        $("#saveCouponid").click(function(){

            var couponstatus=$("#couponstatus").val();
            if(couponstatus==null || couponstatus.length==0){
                alert("状态不能为空！");
                return  false;
            }
           /* var state= $("#coupon_state").html();
            alert(state);
           if(state=="未使用"){
                $("#couponstatus option[value='1']").attr("selected");
            }
            else  if(state=="已使用"){
                $("#couponstatus option[value='2']").attr("selected");
            }
            else  if(state=="未激活")
            {
                $("#couponstatus option[value='3']").attr("selected");
            }*/
            $.ajax({
                type:"POST",
                url:interfaceAddress+"updateCoupon?admin_id="+admin_id+"&couponid="+id+"&couponstatus="+couponstatus,
                data:$("#addForm").serialize(),
                async:true,
                dataType:"json",
                beforeSend: function () {
                    initial_deal();
                },
                success:function(data){
                    closeWaitDialog();
                    if(data.status == "200"){
                        alert("修改成功！");
                        window.location.reload();
                    }else{
                        alert(data.info);
                    }
                },
                error: function () {
                    closeWaitDialog();
                    alert("服务端出错！");
                }
            });
        });
       //优惠券状态动态加载
        function setOption1(){
            //下拉列表值加载出来
            var couponstatus = get_coupon();
            fillOption1("couponstatus",couponstatus);


        }
        //删除优惠券
        function delCoupon(){
            $.ajax({
                type:"POST",
                url:interfaceAddress+"delCoupon?admin_id="+admin_id+"&couponid="+id,
                async:true,
                dataType:"json",
                beforeSend: function () {
                    initial_deal();
                },
                success:function(data){
                    closeWaitDialog();
                    console.log(data);
                    if(data.status == "200"){
                        alert("删除成功！");
                        window.location.reload();
                    }else{
                        alert(data.info);
                    }
                },
                error: function () {
                    closeWaitDialog();
                    alert("服务端出错！");
                }
            });
        }
        /* ---------------------------------------------------- 优惠券datatable表 ------------------------------------------------ */
        function setTable1(aa){
            var f;//用于标记详情页被点击
            //重定义datatable1
            var oTable =
                $("#dynamic-table1").dataTable({
                    "destroy":true,//消除重定义出错
                    "bPaginate":false,//是否使用分页
                    "bFilter": false, //是否使用搜索
                    "sInfo":true,
                    "bAutoWidth":false,
                    "serverSide": false,
                    "oLanguage":{
                        "sInfo": "显示 _START_ 至 _END_ 条 &nbsp;&nbsp;共 _TOTAL_ 条",
                        "sZeroRecords":"没有数据！",
                        "oPaginate": {
                            "sPrevious": " 上一页 ",
                            "sNext":     " 下一页 ",
                        }
                    },
                    "aoColumns":[
                        {"data":"couponid","sTitle":"优惠券_id","sClass":"displayCol","bSortable":false},
                        {"data":"couponname","sTitle":"优惠券名称","bSortable":false},
                        {"data":"coupondetail","sTitle":"描述","bSortable":false},
                        {"data":"couponprice","sTitle":"价格"},
                        {"data":"status","sTitle":"状态"},
                        {"data":" ","sTitle":"操作","bSortable":false,
                            "mRender":function(data,type,full){
                                return "<div class='action-buttons'>" +
                                    "<button id='edit1' class='btn btn-primary btn-xs' style='margin-right:10px' title='编辑'>编辑</button>" +
                                    "<button id='delete1' class='btn btn-danger btn-xs' style='margin-right:10px' title='删除'>删除</button>" +
                                    "</div>";
                            }}
                    ],
                    "aaData":aa,
                });
            $("body").delegate('#dynamic-table1 tr #edit1', 'click', function () {
                f = 1;
            });
            $("body").delegate('#dynamic-table1 tr #delete1', 'click', function () {
                f = 2;
            });

            $("body").delegate('#dynamic-table1 tr', 'click', function () {
                var colData = oTable.fnGetData(this);
                if(colData != null){
                    id = colData.id;
                    couponstatus=colData.couponstatus;
                    $("#coupon_state").html(couponstatus);

                    if(couponstatus=="未使用"){
                        couponstatus=1;
                    }else  if(couponstatus=="已使用"){
                        couponstatus=2;

                    }
                    else
                    {
                        couponstatus=3;
                    }

                }
                if(f == 1){//编辑
                    $("#editCoupon").modal({

                        "backdrop":"static",
                        "keyboard":"true"
                    });
                    fillInfo(colData);
					
                }else if(f == 2){//删除
                    var require = confirm("确认删除优惠券的信息吗");
                    debugger;
                    if(require == true){
                        delCoupon();
                    }else
                        f = 0;
                }
            });
        }



        /////////////////////////////////
        //table checkboxes
        $('th input[type=checkbox], td input[type=checkbox]').prop('checked', false);

        //select/deselect all rows according to table header checkbox
        $('#dynamic-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
            var th_checked = this.checked;//checkbox inside "TH" table header

            $(this).closest('table').find('tbody > tr').each(function(){
                var row = this;
                if(th_checked) tableTools_obj.fnSelect(row);
                else tableTools_obj.fnDeselect(row);
            });
        });

        //select/deselect a row when the checkbox is checked/unchecked
        $('#dynamic-table').on('click', 'td input[type=checkbox]' , function(){
            var row = $(this).closest('tr').get(0);
            if(!this.checked) tableTools_obj.fnSelect(row);
            else tableTools_obj.fnDeselect($(this).closest('tr').get(0));
        });




        $(document).on('click', '#dynamic-table .dropdown-toggle', function(e) {
            e.stopImmediatePropagation();
            e.stopPropagation();
            e.preventDefault();
        });


        //And for the first simple table, which doesn't have TableTools or dataTables
        //select/deselect all rows according to table header checkbox
        var active_class = 'active';
        $('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
            var th_checked = this.checked;//checkbox inside "TH" table header

            $(this).closest('table').find('tbody > tr').each(function(){
                var row = this;
                if(th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
                else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
            });
        });

        //select/deselect a row when the checkbox is checked/unchecked
        $('#simple-table').on('click', 'td input[type=checkbox]' , function(){
            var $row = $(this).closest('tr');
            if(this.checked) $row.addClass(active_class);
            else $row.removeClass(active_class);
        });



        /********************************/
        //add tooltip for small view action buttons in dropdown menu
        $('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});

        //tooltip placement on right or left
        function tooltip_placement(context, source) {
            var $source = $(source);
            var $parent = $source.closest('table')
            var off1 = $parent.offset();
            var w1 = $parent.width();

            var off2 = $source.offset();
            //var w2 = $source.width();

            if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
            return 'left';
        }

    })


</script>
</body>

</html>
